<?php
/* /app/views/helpers/sla.php */

class SlashowHelper extends AppHelper {

    function makeSla($ticket, $DAY, $HOUR, $MINUTE, $SECOND) {
              $i = 0; 
              $sla = 0;
              $counted_sla = '';

              foreach($ticket['TicketSla'] as $res_sla):
                  if(!is_array($res_sla)){
                      $sla +=  $res_sla;
                  }else{
                      $sla +=  $res_sla['response_time'];  
                  }

                  $i++;
              endforeach;

            $sla = ($i != 0)? $sla / $i : $sla;
           if($sla > 0){

/**********    1st     ************/
               if($DAY == 1 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 1){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $day.' days '.$hourrs.' Hours '.$minuter.' minutes '.$second.' seconds';
               }
/**********    2nd     ************/
               if($DAY == 0 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 1){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $hourrs.' Hours '.$minuter.' minutes '.$second.' seconds';
               }
/**********    3rd     ************/
               if($DAY == 0 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 1){
                   $minutes = $sla / 60;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $minuter.' minutes '.$second.' seconds';
               }
/**********    4th     ************/
               if($DAY == 0 && $HOUR == 0 && $MINUTE == 0 && $SECOND == 1){
                   $second = $sla;

                  $counted_sla = $second.' seconds';
               }

/********* 5th  *************/
               if($DAY == 1 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 1){

                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $minute = '.'.$days_explode[1].'';
                   $minutes = $minute * 1440;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $day.' days '.$minuter.' minutes '.$second.' seconds';
               }
/**********    6th     ************/
               if($DAY == 1 && $HOUR == 0 && $MINUTE == 0 && $SECOND == 1){

                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $seconds = '.'.$days_explode[1].'';
                   $second = $seconds * 86400;
                   $second = round($second);

                  $counted_sla = $day.' days '.$second.' seconds';
               }
/**********    7th     ************/
               if($DAY == 1 && $HOUR == 0 && $MINUTE == 0 && $SECOND == 0){
                   $days = $sla / 86400;
                  $counted_sla = round($days).' days';
               }

/************** 8th *****************/

               if($DAY == 1 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 1){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = $hourr[0];
                   
                   $seconds = '.'.$hourr[1].'';
                   $second = $seconds * 3600;
                   $second = round($second);

                  $counted_sla = $day.' days '.$hourrs.' Hours '.$second.' seconds';
               }
/**********    9th     ************/
               if($DAY == 1 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 0){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = round($hourr[0]);
                   
                  $counted_sla = $day.' days '.$hourrs.' Hours ';
               }

/************** 10th *****************/

               if($DAY == 1 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 0){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $day.' days '.$hourrs.' Hours '.$minuter.' minutes';
               }

/************** 11th *****************/

               if($DAY == 0 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 0){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $hourrs.' hours '.$minuter.' minutes';
               }

/************** 12th *****************/

               if($DAY == 0 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 0){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = round($hourr[0]);

                  $counted_sla = $hourrs.' Hours';
               }

/************** 13th *****************/

               if($DAY == 0 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 0){

                   $minute = $sla / 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $minuter.' minutes';
               }

/************** 14th *****************/

               if($DAY == 1 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 0){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $minute = '.'.$days_explode[1].'';
                   $minutes = $minute * 24 * 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $day.' days '.$minuter.' minute';
               }

/************** 15th *****************/

               if($DAY == 0 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 1){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = $hourr[0];
                   
                   $seconds = '.'.$hourr[1].'';
                   $second = $seconds * 3600;
                   $second = round($second);

                  $counted_sla = $hourrs.' hours '.$second.' second';
               }
               return $counted_sla;
         }else{
               $counted_sla = '----'; 
               return $counted_sla;
         }
    }


    function reportSla($sla, $DAY, $HOUR, $MINUTE, $SECOND) {
           if($sla > 0){

/**********    1st     ************/

               if($DAY == 1 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 1){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $day.' days '.$hourrs.' Hours '.$minuter.' minutes '.$second.' seconds';
               }
/**********    2nd     ************/
               if($DAY == 0 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 1){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $hourrs.' Hours '.$minuter.' minutes '.$second.' seconds';
               }
/**********    3rd     ************/
               if($DAY == 0 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 1){
                   $minutes = $sla / 60;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $minuter.' minutes '.$second.' seconds';
               }
/**********    4th     ************/
               if($DAY == 0 && $HOUR == 0 && $MINUTE == 0 && $SECOND == 1){
                   $second = $sla;

                  $counted_sla = $second.' seconds';
               }

/********* 5th  *************/
               if($DAY == 1 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 1){

                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $minute = '.'.$days_explode[1].'';
                   $minutes = $minute * 1440;
                   $minute = explode('.', $minutes);
                   $minuter = $minute[0];
                   
                   $seconds = '.'.$minute[1].'';
                   $second = $seconds * 60;
                   $second = round($second);

                  $counted_sla = $day.' days '.$minuter.' minutes '.$second.' seconds';
               }
/**********    6th     ************/
               if($DAY == 1 && $HOUR == 0 && $MINUTE == 0 && $SECOND == 1){

                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $seconds = '.'.$days_explode[1].'';
                   $second = $seconds * 86400;
                   $second = round($second);

                  $counted_sla = $day.' days '.$second.' seconds';
               }
/**********    7th     ************/
               if($DAY == 1 && $HOUR == 0 && $MINUTE == 0 && $SECOND == 0){
                   $days = $sla / 86400;
                  $counted_sla = round($days).' days';
               }

/************** 8th *****************/

               if($DAY == 1 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 1){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = $hourr[0];
                   
                   $seconds = '.'.$hourr[1].'';
                   $second = $seconds * 3600;
                   $second = round($second);

                  $counted_sla = $day.' days '.$hourrs.' Hours '.$second.' seconds';
               }
/**********    9th     ************/
               if($DAY == 1 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 0){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = round($hourr[0]);
                   
                  $counted_sla = $day.' days '.$hourrs.' Hours ';
               }

/************** 10th *****************/

               if($DAY == 1 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 0){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $hours = '.'.$days_explode[1].'';
                   $hour = $hours * 24;
                   $hourr = explode('.', $hour);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $day.' days '.$hourrs.' Hours '.$minuter.' minutes';
               }

/************** 11th *****************/

               if($DAY == 0 && $HOUR == 1 && $MINUTE == 1 && $SECOND == 0){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = $hourr[0];
                   
                   $minute = '.'.$hourr[1].'';
                   $minutes = $minute * 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $hourrs.' hours '.$minuter.' minutes';
               }

/************** 12th *****************/

               if($DAY == 0 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 0){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = round($hourr[0]);

                  $counted_sla = $hourrs.' Hours';
               }

/************** 13th *****************/

               if($DAY == 0 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 0){

                   $minute = $sla / 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $minuter.' minutes';
               }

/************** 14th *****************/

               if($DAY == 1 && $HOUR == 0 && $MINUTE == 1 && $SECOND == 0){
                   $days = $sla / 86400;
                   $days_explode = explode('.', $days);
                   $day = $days_explode[0];
                   
                   $minute = '.'.$days_explode[1].'';
                   $minutes = $minute * 24 * 60;
                   $minute = explode('.', $minutes);
                   $minuter = round($minute[0]);

                  $counted_sla = $day.' days '.$minuter.' minute';
               }

/************** 15th *****************/

               if($DAY == 0 && $HOUR == 1 && $MINUTE == 0 && $SECOND == 1){
                   $hours = $sla/3600;
                   $hourr = explode('.', $hours);
                   $hourrs = $hourr[0];
                   
                   $seconds = '.'.$hourr[1].'';
                   $second = $seconds * 3600;
                   $second = round($second);

                  $counted_sla = $hourrs.' hours '.$second.' second';
               }
               return $counted_sla;
         }else{
               $counted_sla = '----'; 
               return $counted_sla;
         }
    }
}